package com.mingqijia.gassafety.console.controller.client;

import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.shared.dto.TcConsumerDTO;
import com.mingqijia.gassafety.shared.vcc.VccAuthoritiesProvider;
import com.mingqijia.gassafety.webserver.request.client.BindSubsRequest;
import com.mingqijia.gassafety.webserver.service.CustomerSubsHistoryService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 用户接口
 *
 * @author wanghai
 * @since 2022-06-21
 */

@Slf4j
@RestController(value = "CustomerController")
@RequestMapping("/h5/business/v1/customer")
public class CustomerController {

    @Autowired
    CustomerSubsHistoryService subsHistoryService;

    @Autowired
    VccAuthoritiesProvider vccAuthoritiesProvider;

    @ApiOperation("用户绑定户号")
    @RequestMapping(value = "/subsBind", method = RequestMethod.POST)
    public CommonResponse<Object> subsBind (@RequestBody @Valid BindSubsRequest request){
        subsHistoryService.checkH5Request(request.getOrgId(),request.getPhone(),request.getVccUserId());
        String message = subsHistoryService.bindSubs( request );
        return CommonResponse.success( message );
    }


    @ApiOperation("用户解绑户号")
    @RequestMapping(value = "/subsUnbind", method = RequestMethod.POST)
    public CommonResponse<Object> subsUnbind (@RequestBody @Valid BindSubsRequest request){
        String message = subsHistoryService.unbindSubs( request );
        return CommonResponse.success( message );
    }


    @ApiOperation("查询绑定用户列表")
    @RequestMapping(value = "/bindList", method = RequestMethod.GET)
    public CommonResponse<Object> queryBindList(String orgId, String token) {
        List<TcConsumerDTO> list = vccAuthoritiesProvider.queryBindList(orgId, token);
        log.info("最终用户列表为：{}", list);
        return CommonResponse.success(list);
    }





}
